﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.hud {
    import flash.events.*;
    import flash.display.*;
    import Events.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;
    import Display.MarketUI.*;
    import GameMode.*;
    import flash.text.*;
    import L10n.*;

    public class BuildModeMenu extends MovieClip {

        public const BTN_UP:int = 1;
        public const BTN_OVER:int = 2;
        public const BTN_SET:int = 3;

        public var closeButton:SimpleButton;
        public var giftsButton:MovieClip;
        public var housesButton:MovieClip;
        public var leisureButton:MovieClip;
        public var factoriesButton:MovieClip;
        public var terrainButton:MovieClip;
        public var roadsButton:MovieClip;
        public var buildText:TextField;
        protected var m_callbacks:Object;

        public function BuildModeMenu(){
            this.m_callbacks = {
                giftsButton:this.onGiftsClick,
                roadsButton:this.onRoadClick,
                housesButton:this.makeCatalogClickHandler("residence"),
                leisureButton:this.makeCatalogClickHandler("business"),
                factoriesButton:this.makeCatalogClickHandler("factory"),
                terrainButton:this.makeCatalogClickHandler("decoration")
            };
            super();
            addEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);
        }
        private function onAddedToStage(_arg1:Event):void{
            removeEventListener(Event.ADDED_TO_STAGE, this.onAddedToStage);
            addEventListener(Event.ENTER_FRAME, this.onFrame);
            MovieClipUtil.playAndStop(this, 1, 34, true, this.onMenuReadyCallback);
        }
        private function onMenuReadyCallback():void{
            removeEventListener(Event.ENTER_FRAME, this.onFrame);
            this.addListeners();
            this.clearAllButtons();
            EmbeddedArt.updateFont(this.buildText, true);
            LocaleHelper.localSetting.TextField_adjust(this.buildText, {
                font:EmbeddedArt.DEFAULT_FONT_NAME,
                bold:false
            });
            this.buildText.text = ZLoc.t("Main", "BuildMenuLabel");
        }
        private function onCloseButtonClick(_arg1:MouseEvent):void{
            var event:* = _arg1;
            this.removeListeners();
            MovieClipUtil.playAndStop(this, 35, -1, false, function ():void{
                Global.ui.showBuildMenu(false);
            });
        }
        private function onFrame(_arg1:Event):void{
            var _local2:String;
            var _local3:MovieClip;
            for (_local2 in this.m_callbacks) {
                _local3 = (this[_local2] as MovieClip);
                if (((!((_local3 == null))) && (!((_local3.currentFrame == 1))))){
                    _local3.gotoAndStop(1);
                };
            };
        }
        private function addListeners():void{
            var _local1:String;
            var _local2:MovieClip;
            var _local3:ToolTip;
            this.addEventListener(MouseEvent.MOUSE_MOVE, this.mouseEventKiller);
            this.addEventListener(MouseEvent.MOUSE_DOWN, this.mouseEventKiller);
            this.addEventListener(MouseEvent.MOUSE_UP, this.mouseEventKiller);
            this.addEventListener(MouseEvent.CLICK, this.mouseEventKiller);
            this.closeButton.addEventListener(MouseEvent.CLICK, this.onCloseButtonClick);
            for (_local1 in this.m_callbacks) {
                _local2 = (this[_local1] as MovieClip);
                _local3 = new ToolTip();
                _local3.toolTip = ZLoc.t("Main", ("BuildMenu_" + _local1));
                _local3.attachToolTip(_local2);
                _local2.addEventListener(MouseEvent.CLICK, this.m_callbacks[_local1]);
                _local2.addEventListener(MouseEvent.MOUSE_OVER, this.onButtonMouseOver);
                _local2.addEventListener(MouseEvent.MOUSE_OUT, this.onButtonMouseOut);
                _local2.addEventListener(MouseEvent.MOUSE_DOWN, this.onButtonMouseDown);
            };
        }
        private function removeListeners():void{
            var _local1:String;
            var _local2:MovieClip;
            this.removeEventListener(MouseEvent.MOUSE_MOVE, this.mouseEventKiller);
            this.removeEventListener(MouseEvent.MOUSE_UP, this.mouseEventKiller);
            this.removeEventListener(MouseEvent.MOUSE_DOWN, this.mouseEventKiller);
            this.removeEventListener(MouseEvent.CLICK, this.mouseEventKiller);
            this.closeButton.removeEventListener(MouseEvent.CLICK, this.onCloseButtonClick);
            for (_local1 in this.m_callbacks) {
                _local2 = (this[_local1] as MovieClip);
                _local2.removeEventListener(MouseEvent.CLICK, this.m_callbacks[_local1]);
                _local2.removeEventListener(MouseEvent.MOUSE_OVER, this.onButtonMouseOver);
                _local2.removeEventListener(MouseEvent.MOUSE_OUT, this.onButtonMouseOut);
                _local2.removeEventListener(MouseEvent.MOUSE_DOWN, this.onButtonMouseDown);
            };
        }
        private function onButtonMouseOut(_arg1:MouseEvent):void{
            var _local2:MovieClip = (_arg1.currentTarget as MovieClip);
            if (_local2.currentFrame != this.BTN_SET){
                _local2.gotoAndStop(this.BTN_UP);
            };
        }
        private function onButtonMouseOver(_arg1:MouseEvent):void{
            var _local2:MovieClip = (_arg1.currentTarget as MovieClip);
            if (_local2.currentFrame != this.BTN_SET){
                _local2.gotoAndStop(this.BTN_OVER);
            };
        }
        private function onButtonMouseDown(_arg1:MouseEvent):void{
            this.clearAllButtons();
            (_arg1.currentTarget as MovieClip).gotoAndStop(this.BTN_SET);
        }
        private function clearAllButtons():void{
            var _local1:String;
            for (_local1 in this.m_callbacks) {
                (this[_local1] as MovieClip).gotoAndStop(this.BTN_UP);
            };
        }
        private function mouseEventKiller(_arg1:MouseEvent):void{
            _arg1.stopImmediatePropagation();
        }
        private function onGiftsClick(_arg1:MouseEvent):void{
            this.clearAllButtons();
            UI.displayCatalog("close");
        }
        private function onRoadClick(_arg1:MouseEvent):void{
            this.clearAllButtons();
            UI.displayCatalog("close");
            Global.world.addGameMode(new GMPlaceMapResource("road", Road, false));
        }
        private function makeCatalogClickHandler(_arg1:String):Function{
            var type:* = _arg1;
            return (function (_arg1:MouseEvent):void{
                clearAllButtons();
                (_arg1.currentTarget as MovieClip).gotoAndStop(BTN_SET);
                var _local2:* = UI.displayCatalog(type);
                _local2.addEventListener(CloseEvent.CLOSE, onCatalogClose);
            });
        }
        private function onCatalogClose(_arg1:Event):void{
            var _local2:Catalog = (_arg1.currentTarget as Catalog);
            _local2.removeEventListener(CloseEvent.CLOSE, this.onCatalogClose);
            this.clearAllButtons();
        }

    }
}//package Display.hud 
